<?php

class Admin_CampaignController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        $this->_helper->layout()->disableLayout();
        Zend_Loader::loadFile('../application/admin/models/Campaign.php');
        $Campaign_model = new Campaign();
        $Campaign_arr = $Campaign_model->listCampaigns();
        // print_r($newsletter_arr); EXIT;
        $this->view->Campaign_arr = $Campaign_arr;
     //  print_r($Campaign_arr); EXIT;
    }

     public function editAction()
    {
        $this->_helper->layout()->disableLayout();
        Zend_Loader::loadFile('../application/admin/models/Campaign.php');
        $Campaign_model = new Campaign();
        $Campaign_id = $this->_getParam('id', 0);
        $Campaign_arr = $Campaign_model->getCampaignbyid($Campaign_id);
        $park_arr = $Campaign_model->getnationalparks();
       //  print_r($park_arr); EXIT;
        $this->view->park_arr = $park_arr;
    //   print_r($Campaign_arr); EXIT;
        $this->view->campaign_arr = $Campaign_arr;
         $this->view->campaign_id=$Campaign_id;
    //  print_r($Campaign_arr); EXIT;
    }
     public function doeditAction()
    {
        $this->_helper->layout()->disableLayout();
        Zend_Loader::loadFile('../application/admin/models/Campaign.php');
        $Campaign_model = new Campaign();
         $request = $this->getRequest();
        if ($this->getRequest()->isPost()) {
			$Campaign_model = new Campaign();
			$form_values = $request->getPost();
			$update_Campaign = $Campaign_model->updateCampaign($form_values);
		}
     //  print_r($Campaign_arr); EXIT;
    }


    public function addAction()
    {
        $this->_helper->layout()->disableLayout();
        Zend_Loader::loadFile('../application/admin/models/Campaign.php');
        $Campaign_model = new Campaign();
        $park_arr = $Campaign_model->getnationalparks();
       //  print_r($park_arr); EXIT;
        $this->view->park_arr = $park_arr;
     //  print_r($Campaign_arr); EXIT;
    }
    
    public function doaddAction()
    {
        $this->_helper->layout()->disableLayout();
        Zend_Loader::loadFile('../application/admin/models/Campaign.php');
        $Campaign_model = new Campaign();
         $request = $this->getRequest();
        if ($this->getRequest()->isPost()) {
			$Campaign_model = new Campaign();
			$form_values = $request->getPost();
			$update_Campaign = $Campaign_model->addCampaign($form_values);
		}
    }

    

   	public function updateCampaignAction()
   	{
   		$this->_helper->layout()->disableLayout();
   		Zend_Loader::loadFile('../application/admin/models/Campaign.php');
		Zend_Loader::loadFile('../application/admin/forms/Campaign.php');
        $rate_form = new Form_Campaign();
        $request = $this->getRequest();
        if ($this->getRequest()->isPost()) {            
			$rate_model = new Campaign();
			$form_values = $request->getPost();
			$update_Campaign = $rate_model->updateRate($form_values);
		}
		
		exit;
   	}
    
	public function deletecampaignAction()
    {
        $this->_helper->layout()->disableLayout();
        $id = $this->_getParam('id', 0);
        Zend_Loader::loadFile('../application/admin/models/Campaign.php');
        $Campaign_model = new Campaign();
        $Campaign_model->deleteCampaign($id);
        //$this->_helper->redirector('index');
        exit;
    }

    public function campaignfeaturesAction()
    {
        $this->_helper->layout()->disableLayout();
        Zend_Loader::loadFile('../application/admin/models/Campaign.php');
        $Campaign_model = new Campaign();
        $controller = $this->getRequest()->getControllerName();
        $action = $this->getRequest()->getActionName();
        $this->view->title = "Add new Rate";
        $id = $this->_getParam('id', 0);
        $options = array("action"=>$action, "id"=>$id);
        $structarr=$Campaign_model->getCampaignfeatures($id);
   //   print_r($structarr);exit;
        $this->view->structarr = $structarr;
        $this->view->id = $id;

        
    }

     public function doaddcampaignfeaturesAction()
    {
         $this->_helper->layout()->disableLayout();
        Zend_Loader::loadFile('../application/admin/models/Campaign.php');
        $rate_model = new Campaign();
        $controller = $this->getRequest()->getControllerName();
        $action = $this->getRequest()->getActionName();
         if ($this->getRequest()->isPost()) {
			$rate_model = new Campaign();
			$form_values = $this->getRequest()->getPost();
              //     print_r($form_values);exit;
                $elementarray=array();
                $val=array();
                $key=array();
                $i=0;
                foreach($form_values as $x){
                  foreach($x as $y){
                      switch($y["name"]){
                          case "key":
                              $exkey[]=$y["value"];
                               break;
                          case "val":
                              $exval[]=$y["value"];
                               break;
                           case "val_ru":
                              $exval_ru[]=$y["value"];
                               break;
                          case "id":
                              $elementarray["id"]=$y["value"];


                      }
                  }
                }

                foreach($exkey as $structkeyoptkey=>$structkeyoptval){
                    $elementarray["key"][$structkeyoptkey]=$exkey[$structkeyoptkey];
                    $elementarray["val"][$structkeyoptkey]=$exval[$structkeyoptkey];
                    $elementarray["val_ru"][$structkeyoptkey]=$exval_ru[$structkeyoptkey];
                }

             // print_r($elementarray);exit;
		$update_Campaign = $rate_model->updateCampaignfeatures($elementarray);
          }

           exit;

    }

    public function deletestructuredataAction()
    {
        $this->_helper->layout()->disableLayout();
        Zend_Loader::loadFile('../application/admin/models/Campaign.php');
        $Campaign_model = new Campaign();
        $controller = $this->getRequest()->getControllerName();
        $action = $this->getRequest()->getActionName();
         if ($this->getRequest()->isPost()) {
             $form_values = $this->getRequest()->getPost();
             $deletestrdata = $Campaign_model->deleteCampaignfeatures($form_values);
         }
         
    }

    public function addratesAction()
    {
        $this->_helper->layout()->disableLayout();
        Zend_Loader::loadFile('../application/admin/models/Campaign.php');
        $Campaign_model = new Campaign();
        $id = $this->_getParam('id', 0);
        $this->view->id = $id;
    }
}